package com.lc1993929.tank.behavior;

import com.lc1993929.tank.astar.AStar;
import com.lc1993929.tank.constants.Action;
import com.lc1993929.tank.constants.Condition;
import com.lc1993929.tank.constants.Direction;
import com.lc1993929.tank.constants.TankStatus;
import com.lc1993929.tank.entity.tank.Tank;
import com.lc1993929.tank.entity.vo.DirectionAndDistance;
import com.lc1993929.tank.map.Coord;
import com.lc1993929.tank.map.Node;
import com.lc1993929.tank.util.MapUtil;
import org.springframework.stereotype.Component;

import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * Created by LiuChang on 2018/11/26.
 */
@Component
public class Armata1Behavior {
    public Action behavior() {
        //优先判断能不能打到NPC，如果能秒杀NPC，则优先攻击NPC
        attackNPC();
        if (Condition.myArmata1.tankStatus == TankStatus.ATTACK) {
            return MapUtil.getAction(Condition.myArmata1);
        }
        //第一步寻找复活币
        findResurgence();
        if (Condition.myArmata1.tankStatus == TankStatus.SUERGENCE) {
            //处于前往复活币的状态，不需要执行后续的逻辑
            return MapUtil.getAction(Condition.myArmata1);
        }
        //第二步攻击敌人
        surroundAttack();
        if (Condition.myArmata1.tankStatus == TankStatus.ATTACK) {
            //进入团战逻辑判断是直接打还是需要调整站位
            groupAttack();
            if (Condition.myArmata1.tankStatus == TankStatus.ATTACK) {
                //判断躲避敌方黑豹
                eludeEnemyK2Panther();
                if (Condition.myArmata1.tankStatus == TankStatus.ATTACK) {
                    //如果不用躲避敌方黑豹或已经是最佳站位
                    return MapUtil.getAction(Condition.myArmata1);
                }
            }
        }

        //经过围杀逻辑和团战逻辑后，如果是前往目标点
        if (Condition.myArmata1.tankStatus == TankStatus.TARGET) {
            //判断会不会白挨打
            willBeAttack();
            if (Condition.myArmata1.tankStatus == TankStatus.DIRECTION) {
                //    不会白挨打，冲过去
                return MapUtil.getAction(Condition.myArmata1);
            }
        } else if (Condition.myArmata1.tankStatus == TankStatus.WEI_SHA) {
            return MapUtil.getAction(Condition.myArmata1);
        }
        //如果没有目标或会被挨打，则探图去
        search();
        if (Condition.myArmata1.tankStatus == TankStatus.SEARCH) {
            //    如果结果是要求扫图，则判断会不会白挨打
            willBeAttack();
            if (Condition.myArmata1.tankStatus == TankStatus.DIRECTION) {
                //    不会白挨打
                return MapUtil.getAction(Condition.myArmata1);
            }
        } else if (Condition.myArmata1.tankStatus == TankStatus.FORMATION) {
            //    进入集合逻辑
            boolean toFormation = formation();
            if (!toFormation) {
                //    未集合完毕，优先集合或前往目标点
                willBeAttack();
                if (Condition.myArmata1.tankStatus == TankStatus.DIRECTION) {
                    //    不会白挨打
                    return MapUtil.getAction(Condition.myArmata1);
                }
            }
        } else if (Condition.myArmata1.tankStatus == TankStatus.TARGET) {
            //判断会不会白挨打
            willBeAttack();
            if (Condition.myArmata1.tankStatus == TankStatus.DIRECTION) {
                //    不会白挨打，冲过去
                return MapUtil.getAction(Condition.myArmata1);
            }
        }

        //   判断不动会不会白挨打
        stayWillBeFreeAttack();
        if (Condition.myArmata1.tankStatus == TankStatus.TARGET) {
            return MapUtil.getAction(Condition.myArmata1);
        }
        //不知道怎么弄了
        boring();
        return MapUtil.getAction(Condition.myArmata1);
    }

    /**
     * 判断不动会不会被白打
     */
    private void stayWillBeFreeAttack() {
        Integer canBeAttackNum = MapUtil.getCanBeAttackNum(Condition.myArmata1.coord);
        Coord bestCoord = Condition.gameMap.myBestCoord(Condition.myArmata1);
        if (canBeAttackNum > 1 && !Condition.myArmata1.coord.equals(bestCoord)) {
            Condition.myArmata1.tankStatus = TankStatus.TARGET;
            Condition.myArmata1.targetCoord = bestCoord;
        } else if (canBeAttackNum == 1 && MapUtil.canAttackEnemyList(Condition.myArmata1).isEmpty() && !Condition.myArmata1.coord.equals(bestCoord)) {
            //判断有没有被对方白打，如果被白打了，调整站位
            Condition.myArmata1.tankStatus = TankStatus.TARGET;
            Condition.myArmata1.targetCoord = bestCoord;
        } else if (canBeAttackNum == 1 && MapUtil.canAttackEnemyList(Condition.myArmata1).isEmpty() && Condition.myArmata1.coord.equals(bestCoord)) {
            //站着不动也会白挨打，冲上去
            List<Coord> bestCoords = Condition.gameMap.myBestCoordsExceptSelf(Condition.myArmata1);
            // 去往可移动坐标中，受到攻击最低的且可以攻击到敌人的坐标
            Condition.myArmata1.tankStatus = TankStatus.TARGET;
            Integer minEnemyValue = Condition.gameMap.getEnemyValue(bestCoords.stream().min(Comparator.comparingInt(value -> Condition.gameMap.getEnemyValue(value))).get());
            Condition.myArmata1.targetCoord = bestCoords.stream().filter(coord -> Condition.gameMap.getEnemyValue(coord).equals(minEnemyValue))
                    .max(Comparator.comparingInt(value -> MapUtil.canAttackEnemyList(Condition.myArmata1, value).size())).get();
        } else {
            if (Condition.enemyWZ123.coord == null && Condition.enemyWZ123.shengyushengming > 0 && Condition.myArmata1.isBeAttacked) {
                //如果正在被白挨打，调整站位
                List<Coord> bestCoords = Condition.gameMap.myBestCoords(Condition.myArmata1);
                bestCoords.remove(Condition.myArmata1.coord);
                if (bestCoords.isEmpty()) {
                    //    不动会被白挨打，还不如冲上去
                    Condition.myArmata1.tankStatus = TankStatus.TARGET;
                    Tank enemyTank = MapUtil.getMinDistanceEnemyTank(Condition.myArmata1);
                    Condition.myArmata1.targetCoord = enemyTank.coord;
                } else {
                    Condition.myArmata1.tankStatus = TankStatus.TARGET;
                    Condition.myArmata1.targetCoord = bestCoords.stream().min(Comparator.comparingInt(value -> Condition.gameMap.getEnemyValue(value))).get();
                }
            }
        }
    }

    private void willBeAttack() {
        //走位之前要判断目标点会不会白挨打
        DirectionAndDistance directionAndDistance = MapUtil.armataFindNextCoord(Condition.myArmata1);
        Coord nextCoord = MapUtil.getNextCoord(directionAndDistance, Condition.myArmata1.coord);
        boolean canArrive = MapUtil.coordCanArrive(nextCoord);
        if (canArrive) {
            nextNodeDanger(nextCoord);
        }
        if (!canArrive || Condition.myArmata1.tankStatus == TankStatus.ATTACK && directionAndDistance.getDistance() > 1) {
            //  如果跑太快不行，试试跑慢一步
            directionAndDistance.setDistance(directionAndDistance.getDistance() - 1);
            nextCoord = MapUtil.getNextCoord(directionAndDistance, Condition.myArmata1.coord);
            nextNodeDanger(nextCoord);
            if (Condition.myArmata1.tankStatus == TankStatus.ATTACK) {
                //    所有走位都不行，去开图
                Condition.myArmata1.tankStatus = TankStatus.SEARCH;
            } else {
                Condition.myArmata1.targetDistance = directionAndDistance.getDistance();
            }
        } else {
            //    过去打架
            Condition.myArmata1.targetDistance = directionAndDistance.getDistance();
        }
    }

    /**
     * 躲避敌方黑豹
     */
    private void eludeEnemyK2Panther() {
        if (Condition.enemyK2Panther.coord != null && Condition.enemyK2Panther.shengyushengming > 0) {
            //判断敌方黑豹受到的友方集火火力
            List<Tank> myCanAttack = MapUtil.getAllMyCanAttack(Condition.enemyK2Panther.coord);
            Integer enemyK2PantherWillBeAttack = Condition.gameMap.getMyValue(Condition.enemyK2Panther.coord);
            boolean myCanAttackEnemyK2Panther = MapUtil.myCanAttack(Condition.myArmata1, Condition.enemyK2Panther.coord);
            boolean enemyK2PantherCanAttackMe = MapUtil.enemyCanAttack(Condition.enemyK2Panther, Condition.myArmata1.coord);
            if (myCanAttackEnemyK2Panther && Condition.enemyK2Panther.shengyushengming <= Condition.myArmata1.gongji) {
                //如果敌方黑豹可以被秒杀，则攻击它
                Condition.myArmata1.tankStatus = TankStatus.ATTACK;
                Condition.myArmata1.targetDirection = MapUtil.getDirection(Condition.myArmata1.coord, Condition.enemyK2Panther.coord);
            } else if (myCanAttack.size() == 2 && myCanAttackEnemyK2Panther) {
                boolean runAway = myCanAttack.stream().anyMatch(tank -> tank.action != null && tank.action.getType() == Action.Type.MOVE);
                //    敌方黑豹正在被两个友方单位攻击，看另一个友方单位会不会跑路，且本坦克能攻击到敌方黑豹
                if (runAway) {
                    Coord bestCoord = Condition.gameMap.myBestCoord(Condition.myArmata1);
                    if (Condition.myArmata1.coord.equals(bestCoord)) {
                        //如果已经是最佳站位了，按照优先级进行攻击
                        List<Tank> enemyTanks = MapUtil.canAttackEnemyList(Condition.myArmata1);
                        MapUtil.groupAttackSurround(enemyTanks, Condition.myArmata1);
                    } else {
                        //否则进行走位
                        Condition.myArmata1.tankStatus = TankStatus.TARGET;
                        Condition.myArmata1.targetCoord = bestCoord;
                    }
                } else {
                    Condition.myArmata1.tankStatus = TankStatus.ATTACK;
                    Condition.myArmata1.targetDirection = MapUtil.getDirection(Condition.myArmata1.coord, Condition.enemyK2Panther.coord);
                }
            } else if (enemyK2PantherWillBeAttack > 1 && myCanAttackEnemyK2Panther) {
                //    敌方黑豹可以被集火，且本坦克能攻击到敌方黑豹
                Condition.myArmata1.tankStatus = TankStatus.ATTACK;
                Condition.myArmata1.targetDirection = MapUtil.getDirection(Condition.myArmata1.coord, Condition.enemyK2Panther.coord);
            } else {
                if (enemyK2PantherCanAttackMe) {
                    //如果可以被敌方黑豹攻击，判断有没有最佳站位
                    Coord bestCoord = Condition.gameMap.myBestCoord(Condition.myArmata1);
                    if (Condition.myArmata1.coord.equals(bestCoord)) {
                        //如果已经是最佳站位了，按照优先级进行攻击
                        List<Tank> enemyTanks = MapUtil.canAttackEnemyList(Condition.myArmata1);
                        MapUtil.groupAttackSurround(enemyTanks, Condition.myArmata1);
                    } else {
                        //否则进行走位
                        Condition.myArmata1.tankStatus = TankStatus.TARGET;
                        Condition.myArmata1.targetCoord = bestCoord;
                    }
                }
            }
        }
    }

    /**
     * 判断下一移动地点是否危险
     */
    private void nextNodeDanger(Coord nextCoord) {
        List<Tank> enemyTanks = MapUtil.enemyCanAttackSum(nextCoord);
        if (enemyTanks.size() > 1) {
            //目标点太危险，不去
            Condition.myArmata1.tankStatus = TankStatus.ATTACK;
            Condition.gameMap.start = new Node(Condition.myArmata1.coord);
            Condition.gameMap.end = new Node(MapUtil.getNearestEnemyCoord(Condition.myArmata1));
            Condition.myArmata1.targetDirection = AStar.findNextStep(Condition.gameMap);
        } else if (enemyTanks.size() == 1) {
            Tank enemyTank = enemyTanks.get(0);
            //    判断是否有队友正在与目标交战
            List<Tank> myTanks = MapUtil.getAllMyCanAttack(enemyTank.coord);
            if (!myTanks.isEmpty()) {
                if (enemyTank.gongji > 1 && Condition.gameMap.getMyValue(enemyTank.coord) < 2) {
                    //    这辆坦克是敌方黑豹，且没有被集火，不去招惹它
                    Condition.myArmata1.tankStatus = TankStatus.ATTACK;
                    Condition.gameMap.start = new Node(Condition.myArmata1.coord);
                    Condition.gameMap.end = new Node(MapUtil.getNearestEnemyCoord(Condition.myArmata1));
                    Condition.myArmata1.targetDirection = AStar.findNextStep(Condition.gameMap);
                } else {
                    Condition.myArmata1.tankStatus = TankStatus.DIRECTION;
                    Condition.myArmata1.targetDirection = MapUtil.getDirection(Condition.myArmata1.coord, nextCoord);
                }
            } else {
                //没有队友于目标交战，不去挨预判炮
                Condition.myArmata1.tankStatus = TankStatus.ATTACK;
                Condition.gameMap.start = new Node(Condition.myArmata1.coord);
                Condition.gameMap.end = new Node(MapUtil.getNearestEnemyCoord(Condition.myArmata1));
                Condition.myArmata1.targetDirection = AStar.findNextStep(Condition.gameMap);
            }

        } else {
            Condition.myArmata1.tankStatus = TankStatus.DIRECTION;
            Condition.myArmata1.targetDirection = MapUtil.getDirection(Condition.myArmata1.coord, nextCoord);
        }
    }

    /**
     * 发现了NPC就冲过去包围或者去包围正在和友军交战的敌方，否则就去探图
     */
    private void surroundAttack() {
        List<Tank> enemyTanks = MapUtil.canAttackEnemyList(Condition.myArmata1);
        MapUtil.groupAttackSurround(enemyTanks, Condition.myArmata1);
    }

    /**
     * 抢复活币的逻辑
     */
    private void findResurgence() {
        // 判断是否已有复活币目标，如果有目标且目标复活币还存在，则直接去目标复活币，如果有目标复活币，但目标复活币已经消失则修改目标
        if (Condition.myArmata1.tankStatus == TankStatus.SUERGENCE) {
            boolean anyMatch = Condition.resurgenceCoords.stream().anyMatch(
                    coord -> Condition.myArmata1.targetCoord != null && Condition.myArmata1.targetCoord.equals(coord)
            );
            if (anyMatch) {
                //如果已有目标复活币且目标复活币还存在，则不对该坦克做任何修改
                return;
            }
        }
        //如果没有目标复活币或目标复活币已消失，则搜寻其它附近的复活币
        //  判断地图上是否还有复活币
        if (!Condition.resurgenceCoords.isEmpty()) {
            List<Coord> nearbyResurgenceCoords = Condition.resurgenceCoords.stream().filter(coord -> {
                //计算自己离该复活币的距离
                int myArmata1Distance = AStar.calcH(coord, Condition.myArmata1.coord);
                //    判断该复活币附近是否有己方坦克比自己离复活币近
                if (Condition.myK2Panther.shengyushengming > 0 && myArmata1Distance > AStar.calcH(coord, Condition.myK2Panther.coord) * 2) {
                    return false;
                } else if (Condition.myArmata2.shengyushengming > 0 && myArmata1Distance > AStar.calcH(coord, Condition.myArmata2.coord)) {
                    return false;
                } else if (Condition.myWZ123.shengyushengming > 0 && myArmata1Distance > AStar.calcH(coord, Condition.myWZ123.coord) * 2) {
                    return false;
                } else
                    return Condition.myT90.shengyushengming <= 0 || myArmata1Distance <= AStar.calcH(coord, Condition.myT90.coord) * 2;
            }).collect(Collectors.toList());
            if (!nearbyResurgenceCoords.isEmpty()) {
                //没有友方坦克比自己离这些复活币更近，前往找到的复活币中的最近的地址
                //将坦克状态设置为抢复活币，并修改坦克目标
                Condition.myArmata1.targetCoord = nearbyResurgenceCoords.stream().min(Comparator.comparingInt(coord -> AStar.calcH(coord, Condition.myArmata1.coord))).get();
                Condition.myArmata1.tankStatus = TankStatus.SUERGENCE;
            } else {
                Condition.myArmata1.tankStatus = TankStatus.SEARCH;
            }
        } else {
            //    如果无法找到复活币目标或没有离自己近的复活币，则将坦克状态至为开图状态
            Condition.myArmata1.tankStatus = TankStatus.SEARCH;
        }

    }


    /**
     * 团战逻辑
     */
    private void groupAttack() {
        Integer enemyValueSum = MapUtil.getEnemyValueSum();
        Integer myValueSum = MapUtil.getMyValueSum();
        List<Tank> enemyTanks = MapUtil.canAttackEnemyList(Condition.myArmata1);
        boolean canSecKill = enemyTanks.stream().anyMatch(tank -> tank.shengyushengming <= Condition.myArmata1.gongji);
        List<Tank> enemyCanAttackSum = MapUtil.enemyCanAttackSum(Condition.myArmata1.coord);
        Integer canBeAttackNum = enemyCanAttackSum.size();
        if (canSecKill && canBeAttackNum <= 2) {
            Tank enemyTank = enemyTanks.stream().filter(tank -> tank.shengyushengming <= Condition.myArmata1.gongji).max(Comparator.comparingInt(tank -> tank.gongji)).get();
            Integer enemyValue = Condition.gameMap.getEnemyValue(Condition.myArmata1.coord);
            if (enemyValue <= 2 || enemyTank.gongji > 1) {
                Condition.myArmata1.tankStatus = TankStatus.ATTACK;
                Condition.myArmata1.targetDirection = MapUtil.getDirection(Condition.myArmata1.coord, enemyTank.coord);
            }
        } else if (myValueSum > enemyValueSum && Condition.gameMap.getEnemyValue(Condition.myArmata1.coord) < 4 && !enemyTanks.isEmpty()) {
            //  应该找出能打到的列表，优先打血量少的敌人
            MapUtil.groupAttackSurround(enemyTanks, Condition.myArmata1);
        } else if (myValueSum.equals(enemyValueSum) && Condition.gameMap.getEnemyValue(Condition.myArmata1.coord) < 4 && !enemyTanks.isEmpty()) {
            //  如果双方火力相等，则判断是否已经找完复活币和NPC
            if (Condition.residueGoldNum <= 0 && (Condition.npc.shengyushengming <= 0 || Condition.npc.coord != null)) {
                MapUtil.groupAttackSurround(enemyTanks, Condition.myArmata1);
            } else {
                Condition.myArmata1.tankStatus = TankStatus.SEARCH;
            }
        } else {
            Coord bestCoord = Condition.gameMap.myBestCoord(Condition.myArmata1);
            if (canBeAttackNum > 1 && !Condition.myArmata1.coord.equals(bestCoord)) {
                //    是我方受到威胁最大的坦克并且没有到达最佳站位,调整站位
                Condition.myArmata1.tankStatus = TankStatus.TARGET;
                Condition.myArmata1.targetCoord = bestCoord;
            } else if (canBeAttackNum == 1 && MapUtil.canAttackEnemyList(Condition.myArmata1).isEmpty() && !Condition.myArmata1.coord.equals(bestCoord)) {
                //判断有没有被对方白打，如果被白打了，调整站位
                Condition.myArmata1.tankStatus = TankStatus.TARGET;
                Condition.myArmata1.targetCoord = bestCoord;
            } else {
                //不是我方受到威胁最大的坦克，或者已经是最佳站位了
                MapUtil.groupAttackSurround(enemyTanks, Condition.myArmata1);
            }
        }
    }


    /**
     * 开图的逻辑
     */
    private void search() {
        if (Condition.residueGoldNum <= 0 && Condition.npc.shengyushengming <= 0) {
            //    复活币都被捡完了并且NPC死了，直接集合
            Condition.myArmata1.tankStatus = TankStatus.FORMATION;
            return;
        }
        if (Condition.residueGoldNum <= 0 && Condition.npc.coord != null && Condition.npc.shengyushengming > 0) {
            //复活币被抢完了，NPC还没死，去搞npc
            Condition.myArmata1.tankStatus = TankStatus.TARGET;
            Condition.myArmata1.targetCoord = Condition.npc.coord;
            return;
        }
        //如果已有开图目标点且目标点还存在，则不做任何修改
        if (Condition.myArmata1.tankStatus == TankStatus.SEARCH) {
            boolean anyMatch = Condition.mistyCoords.stream().anyMatch(coord -> Condition.myArmata1.targetCoord != null && Condition.myArmata1.targetCoord.equals(coord));
            if (anyMatch) {
                //如果已有目标迷雾且目标迷雾还存在，则不对该坦克做任何修改
                return;
            }
        }
        //没有目标迷雾或迷雾已消失，则找最近的迷雾开图
        if (!Condition.mistyCoords.isEmpty()) {
            Condition.myArmata1.tankStatus = TankStatus.SEARCH;
            Optional<Coord> optional = Condition.mistyCoords.stream().filter(coord -> AStar.calcH(coord, Condition.myArmata2.coord) > AStar.calcH(coord, Condition.myArmata1.coord))
                    .min(Comparator.comparingInt(coord -> AStar.calcH(coord, Condition.myArmata1.coord)));
            Condition.myArmata1.targetCoord = optional.orElseGet(() -> Condition.mistyCoords.stream().min(Comparator.comparingInt(coord -> AStar.calcH(coord, Condition.myArmata1.coord))).get());
        } else {
            //    如果已经没有迷雾或没有离自己近的迷雾，则将坦克状态至为集合状态
            Condition.myArmata1.tankStatus = TankStatus.FORMATION;
        }
    }

    /**
     * 集合的逻辑
     */
    private boolean formation() {
        Condition.myArmata1.tankStatus = TankStatus.FORMATION;
        Coord targetCoord;
        if (Condition.myT90.shengyushengming > 0) {
            targetCoord = Condition.myT90.coord;
        } else if (Condition.myK2Panther.shengyushengming > 0) {
            targetCoord = Condition.myK2Panther.coord;
        } else if (Condition.myWZ123.shengyushengming > 0) {
            targetCoord = Condition.myWZ123.coord;
        } else if (Condition.myArmata2.shengyushengming > 0) {
            targetCoord = Condition.myArmata2.coord;
        } else {
            //  队友都死完了，找个死角缩着打
            Condition.myArmata1.tankStatus = TankStatus.TARGET;
            targetCoord = Condition.gameMap.findADeadAngle();
        }
        Condition.myArmata1.targetCoord = targetCoord;
        //    判断是否已经集合完成
        if (Condition.myArmata1.tankStatus == TankStatus.FORMATION && MapUtil.nearTarget(Condition.myArmata1.coord, targetCoord)) {
            //返回集合成功
            return true;
        } else {
            //返回到达目标死角
            return Condition.myArmata1.tankStatus == TankStatus.TARGET && Condition.myArmata1.coord == targetCoord;
        }
    }

    /**
     * 攻击NPC的逻辑
     */
    private void attackNPC() {
        //判断能不能打到NPC
        Direction direction = MapUtil.attackNPC(Condition.myArmata1);
        if (direction != Direction.WAIT) {
            if (Condition.assistedNPC) {
                Condition.myArmata1.tankStatus = TankStatus.ATTACK;
                Condition.myArmata1.targetDirection = direction;
                return;
            } else {
                //    判断敌方攻击力
                Integer enemyValue = Condition.gameMap.getEnemyValue(Condition.npc.coord);
                if (enemyValue > 1) {
                    Integer myValue = Condition.gameMap.getMyValue(Condition.npc.coord);
                    //获取npc血量除以敌方攻击力的余数
                    int i = Condition.npc.shengyushengming % enemyValue;
                    if (i > myValue || i == 0) {
                        //    如果余数大于我方攻击力，则垫刀
                        Condition.myArmata1.tankStatus = TankStatus.ATTACK;
                        Condition.myArmata1.targetDirection = direction;
                        //    修改npc的剩余血量
                        Condition.npc.shengyushengming = Condition.npc.shengyushengming - Condition.myArmata1.gongji;
                        return;
                    }
                }
            }
        }
        //    如果不能打到NPC或打不死NPC，先去找复活币
        Condition.myArmata1.tankStatus = TankStatus.SUERGENCE;

    }

    /**
     * 什么都做不了的逻辑
     */
    private void boring() {
        //    NPC也打不到，那就朝一个最近的敌方单位的方向来一炮
        Condition.myArmata1.tankStatus = TankStatus.ATTACK;
        Condition.gameMap.start = new Node(Condition.myArmata1.coord);
        Condition.gameMap.end = new Node(MapUtil.getNearestEnemyCoord(Condition.myArmata1));
        Direction nextStep = AStar.findNextStep(Condition.gameMap);
        Condition.myArmata1.targetDirection = nextStep;
    }
}
